package com.mysterymall.Model.Entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * id, 时间 基类
 * @ClassName com.mysterymall.Model.entity
 * @Description
 * @Author HuangWX
 * @Time 2023/11/03  00:59
 */
@Data
public abstract class  BaseEntity {

    // 主键自动注入(ASSIGN_UUID 为不含-的UUID)
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Instant createTime;


    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    private Instant  updateTime;


    public String getShanghaiCreateTime(){
        return this.toString(createTime);
    }

    public String getShanghaiUpdateTime(){
       return this.toString(updateTime);
    }
    
    private String toString(Instant time){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.ofInstant(time, ZoneId.of("Asia/Shanghai")).format(formatter);
    }

}
